package org.feidao.chapter65.consumer;

import com.rabbitmq.client.Channel;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * Created by linghufeixia on 2022-12-27.
 * direct listener
 */
@Component
@Slf4j
public class DirectListener {

    /**
     * .接收队列direct_queue_A的数据
     */
    @RabbitListener(queues = {"direct_queue_A"})
    public void receiveDataFromQueueA(Message message, Channel channel) throws IOException {
        long tag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(tag, true);
        log.info("------------direct consumer begin------------");
        log.info("queue: fanout_queue_A");
        log.info("receive Data: " + new String(message.getBody()));
        log.info("------------direct consumer end------------");
    }

    /**
     * .接收队列direct_queue_B的数据
     */
    @RabbitListener(queues = {"direct_queue_B"})
    public void receiveDataFromQueueB(Message message, Channel channel) throws IOException {
        long tag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(tag, true);
        log.info("------------direct consumer begin------------");
        log.info("queue: fanout_queue_B");
        log.info("receive Data: " + new String(message.getBody()));
        log.info("------------direct consumer end------------");
    }
}
